package com.purchase.ml.service.dealer.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.purchase.ml.bean.req.dealer.SysAddrEditDto;
import com.purchase.ml.bean.req.dealer.SysDealerNewDto;
import com.purchase.ml.consts.Constants;
import com.purchase.ml.entity.acc.SysUser;
import com.purchase.ml.entity.dealer.SysAddr;
import com.purchase.ml.entity.dealer.SysDealer;
import com.purchase.ml.enums.SysSeqNameEnum;
import com.purchase.ml.mapper.dealer.SysAddrMapper;
import com.purchase.ml.mapper.dealer.SysDealerMapper;
import com.purchase.ml.security.JwtUtil;
import com.purchase.ml.service.common.CommonSeqService;
import com.purchase.ml.service.dealer.SysAddrService;
import com.purchase.ml.service.dealer.SysDealerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @author :zxm
 * @date :2021/2/25 11:15
 * @description :some description
 **/
@Service
@Slf4j
public class SysAddrServiceImpl extends ServiceImpl<SysAddrMapper, SysAddr> implements SysAddrService {
    @Autowired
    SysAddrMapper sysAddrMapper;
    @Autowired
    SysDealerMapper sysDealerMapper;

    @Override
    @Transactional
    public void editAddr(SysAddrEditDto dto) {
        SysUser sysUser  = JwtUtil.getCurrentUser();
        SysDealer sysDealer = sysDealerMapper.selectByDealerId(sysUser.getDealerId());
        //值允许修改自己的

        if(dto.getBillingAddr() != null){
            QueryWrapper<SysAddr> wrapper =  new QueryWrapper<>();
            wrapper.eq("addr_id",sysDealer.getBillingAddrId());
            sysAddrMapper.update(dto.getBillingAddr(),wrapper);
        }
        if(dto.getShopAddr() != null){
            QueryWrapper<SysAddr> wrapper =  new QueryWrapper<>();
            wrapper.eq("addr_id",sysDealer.getShopAddrId());
            sysAddrMapper.update(dto.getShopAddr(),wrapper);
        }
    }
}
